package com.cl.short_video_java.web.log;

import com.cl.short_video_java.annotation.IsRole;
import com.cl.short_video_java.annotation.Log;
import com.cl.short_video_java.annotation.Login;
import com.cl.short_video_java.common.Const;
import com.cl.short_video_java.common.Result;
import com.cl.short_video_java.mapper.SysOperLogMapper;
import com.cl.short_video_java.menum.BusinessType;
import com.cl.short_video_java.pojo.SysOperLog;
import com.cl.short_video_java.service.SysOperLogService;
import com.cl.short_video_java.vo.sys.OperLogExceSearch;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
@RequestMapping("/operlog")
public class SysOperLogController {
    @Resource
    private SysOperLogService sysOperLogService;

	private SysOperLogMapper sysOperLogMapper;

	/**
	 * 删除
	 *
	 * @param idlist
	 * @return Boolean
	 */
	@PostMapping("/del")
	@Log(title = "操作日志", businessType = BusinessType.DELETE)
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 14)
	public Result delete(@RequestParam String idlist) {
		return Result.success(sysOperLogService.deleteService(idlist));
	}

	/**
	 * 清除所有操作日志数据
	 *
	 * @return Boolean
	 */
	@PostMapping("/clear")
	@Log(title = "清空操作日志", businessType = BusinessType.OTHER)
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 14)
	public Result clearOperLog() {
		return Result.success(sysOperLogService.clearOperLogService());
	}

    /**
     * 分页查询（搜索）
     * @param operLogExceSearch
     * @return
     */
    @PostMapping("/page")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 14)
    public Result pageSearch(@RequestBody OperLogExceSearch operLogExceSearch){
        return Result.success(sysOperLogService.pageSearchService(operLogExceSearch));
    }

	/**
	 * 导出数据
	 *
	 * @param operLogExceSearch 参数：
	 * @return
	 * @throws IOException
	 */
	@PostMapping("/exce")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 14)
	@Log(title = "日志导出",businessType = BusinessType.OTHER)
	public ResponseEntity<byte[]> getExce(@RequestBody OperLogExceSearch operLogExceSearch) throws IOException {
		return sysOperLogService.getExceService(operLogExceSearch);
	}

	@GetMapping("/list")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 14)
	public Result getList(@RequestParam("num") Integer num, @RequestParam("size") Integer size) {
        return Result.success(sysOperLogService.homePage(num,size));
	}
}
